package gameUtils;

import games.Main;

import java.awt.Point;

/**
 * 
 * @author batata
 *	Some Math operations to support the game
 */
public class GameMath {

	/**
	 * Converts a point from the GUI to a Coordinate
	 * @param p - the specified point from GUI
	 * @return Coordinate - the object Coordinate
	 */
	public static Coordinate convertToGameCoordinate(final Point p){
		return new Coordinate((int)(p.getX()/Main.SQUARE_DIMENSION.getWidth()),(int)(p.getY()/Main.SQUARE_DIMENSION.getHeight()));
	}


	public static Point convertToPoint(final Coordinate c){
		return new Point((int)(c.getAbcissa()*Main.SQUARE_DIMENSION.getWidth()),(int)(c.getOrdinate()*Main.SQUARE_DIMENSION.getHeight()));
	}
	
	public static String convertToString(final Integer key){
		return  "" + (char)(key.intValue());
	}
	
	public static int distanceBetween(final Coordinate c1, final Coordinate c2){
		return (int) Math.pow( (Math.pow(c1.getAbcissa() - c2.getAbcissa(), 2)) + (Math.pow(c1.getOrdinate() -  c2.getOrdinate(), 2)) , (1/2));
	}
	
	public static boolean isNumber(final String word){
		for (int i = 0; i < word.length(); i++) {
			if(!Character.isDigit(word.charAt(i))){
				return false;
			}
		}
		return true;
	}
	
}
